﻿<Window x:Class="WeatherReport.MainWindow" x:Name="MainWindowRoot"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ctlr="clr-namespace:WeatherReport"
        xmlns:vm="clr-namespace:WeatherReport.ViewModels"
        xmlns:tc="clr-namespace:WeatherReport.Converters"
        Title="Weather" Height="240" Width="240" Background="#6685A8" WindowStyle="None"
        WindowStartupLocation="CenterScreen"
        MouseDown="Window_MouseDown">
    
    <Window.Resources>
        <vm:ViewModelLocator x:Key="ViewModelLocator"/>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibility" />
        <tc:InfoDisplayStatusToBrushConverter x:Key="InfoDisplayStatusToBrush" NormalColor="#00FF77" ErrorColor="#E55B49" />
        <LinearGradientBrush x:Key="CircularBevelBrush">
            <GradientStop Offset="0" Color="#2E3D4C"/>
            <GradientStop Offset="1" Color="#B6D2EF"/>
        </LinearGradientBrush>

        <LinearGradientBrush x:Key="ScrewEdgeBrush">
            <GradientStop Offset="0" Color="#B6D2EF"/>
            <GradientStop Offset="0.5" Color="#2E3D4C"/>
            <GradientStop Offset="1" Color="#B6D2EF"/>
        </LinearGradientBrush>

        <ControlTemplate x:Key="CloseButtonTemplate">
            <ControlTemplate.Resources>
                <SolidColorBrush x:Key="CloseButtonXInactive" Color="#FCDCD9" />
                <SolidColorBrush x:Key="CloseButtonXActive" Color="#FFF0EF" />
            </ControlTemplate.Resources>
            <Viewbox>
                <Canvas Width="8" Height="8">
                    <Ellipse x:Name="CloseButtonEllipse" Width="8" Height="8" 
                             Stroke="{StaticResource CircularBevelBrush}" StrokeThickness="0.5">
                        <Ellipse.Fill>
                            <RadialGradientBrush GradientOrigin="0.4,0.4">
                                <GradientStop Offset="0" Color="#D69D98"/>
                                <GradientStop Offset="0.5" Color="#B3594C"/>
                                <GradientStop Offset="1" Color="#A7574D"/>
                            </RadialGradientBrush>
                        </Ellipse.Fill>
                    </Ellipse>
                    <!---->
                    <Line x:Name="CloseButtonX1" X1="3" Y1="3" X2="5" Y2="5"
                          Stroke="{StaticResource CloseButtonXInactive}" StrokeThickness="0.7" 
                          StrokeStartLineCap="Round" StrokeEndLineCap="Round" />
                    <Line x:Name="CloseButtonX2" X1="3" Y1="5" X2="5" Y2="3"
                          Stroke="{StaticResource CloseButtonXInactive}" StrokeThickness="0.7" 
                          StrokeStartLineCap="Round" StrokeEndLineCap="Round" />
                </Canvas>
            </Viewbox>
            
            <ControlTemplate.Triggers>
                <Trigger Property="Button.IsMouseOver" Value="True">
                    <Setter TargetName="CloseButtonEllipse" Property="Fill">
                        <Setter.Value>
                            <RadialGradientBrush GradientOrigin="0.4,0.4">
                                <GradientStop Offset="0" Color="#ECAAA2"/>
                                <GradientStop Offset="0.5" Color="#D04935"/>
                                <GradientStop Offset="1" Color="#BB574A"/>
                            </RadialGradientBrush>
                        </Setter.Value>
                    </Setter>
                    <Setter TargetName="CloseButtonX1" Property="Stroke" Value="{StaticResource CloseButtonXActive}" />
                    <Setter TargetName="CloseButtonX2" Property="Stroke" Value="{StaticResource CloseButtonXActive}" />
                </Trigger>
            </ControlTemplate.Triggers>
            
        </ControlTemplate>
        
        <ControlTemplate x:Key="ToolsButtonTemplate">
            <ControlTemplate.Resources>
                <SolidColorBrush x:Key="ToolsButtonXInactive" Color="#FCDCD9" />
                <SolidColorBrush x:Key="ToolsButtonXActive" Color="#FFF0EF" />
            </ControlTemplate.Resources>
            <Viewbox>
                <Canvas Width="8" Height="8">
                    <Ellipse x:Name="ToolsButtonEllipse" Width="8" Height="8" 
                             Stroke="{StaticResource CircularBevelBrush}" StrokeThickness="0.5">
                        <Ellipse.Fill>
                            <RadialGradientBrush GradientOrigin="0.4,0.4">
                                <GradientStop Offset="0" Color="#98D3A8"/>
                                <GradientStop Offset="0.5" Color="#4CB267"/>
                                <GradientStop Offset="1" Color="#4DA565"/>
                            </RadialGradientBrush>
                        </Ellipse.Fill>
                    </Ellipse>
                    <Path Fill="White" Opacity="0.6" 
                          Data="M 0.4,2.5 Q 0.0,5.8 3.6,5.5 L 6.0,7.6 L 7.8,5.5 L 5.6,3.4 Q 5.4,-0.6 1.4,0.6 L 3.4,2.0 L 3.2,3.2 L 2.2,3.8">
                        <Path.RenderTransform>
                            <TransformGroup>
                                <ScaleTransform CenterX="4.4" CenterY="4.4" ScaleX="0.6" ScaleY="0.6" />
                            </TransformGroup>
                        </Path.RenderTransform>
                    </Path>
                </Canvas>
            </Viewbox>

            <ControlTemplate.Triggers>
                <Trigger Property="Button.IsMouseOver" Value="True">
                    <Setter TargetName="ToolsButtonEllipse" Property="Fill">
                        <Setter.Value>
                            <RadialGradientBrush GradientOrigin="0.4,0.4">
                                <GradientStop Offset="0" Color="#A1EAB5"/>
                                <GradientStop Offset="0.5" Color="#35CE5E"/>
                                <GradientStop Offset="1" Color="#4ABA68"/>
                            </RadialGradientBrush>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </ControlTemplate.Triggers>

        </ControlTemplate>
        
        <Style TargetType="{x:Type Image}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type UIElement}, AncestorLevel=1}, Path=IsEnabled}" Value="False">
                    <Setter Property="Opacity" Value="0.3"></Setter>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>

    <Grid>
        
        <Viewbox Stretch="Fill" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <Grid>
                <Canvas Width="100" Height="100">
                    <Ellipse Width="100" Height="100" Fill="#161616" />

                    <Ellipse Canvas.Left="12.5" Canvas.Top="12.5"
                             Width="75" Height="75" Stroke="#303030" StrokeThickness="0.2" />
                    <Ellipse Canvas.Left="25" Canvas.Top="25"
                             Width="50" Height="50" Stroke="#303030" StrokeThickness="0.2" />

                    <Line X1="0" Y1="50" X2="100" Y2="50" Stroke="#303030" StrokeThickness="0.2" />
                    <Line X1="50" Y1="0" X2="50" Y2="100" Stroke="#303030" StrokeThickness="0.2" />
                    <Line X1="14.64" Y1="85.36" X2="85.36" Y2="14.64" Stroke="#303030" StrokeThickness="0.2" />
                    <Line X1="14.64" Y1="14.64" X2="85.36" Y2="85.36" Stroke="#303030" StrokeThickness="0.2" />                   

                    <Button Canvas.Right="4" Canvas.Top="4" ToolTip="Close" Click="Shutdown_Click"
                            Template="{StaticResource CloseButtonTemplate}" />

                    <Button Canvas.Right="4" Canvas.Bottom="4"
                            Template="{StaticResource ToolsButtonTemplate}"
                            Command="{Binding Source={StaticResource ViewModelLocator}, Path=WeatherViewModel.SettingsCommand}" ToolTip="Settings"
                            Visibility="{Binding Source={StaticResource ViewModelLocator}, Path=WeatherViewModel.IsSettingsButtonVisible, Converter={StaticResource BooleanToVisibility}}" />

                    <ctlr:Screw Canvas.Left="4" Canvas.Top="4" Size="7" SlitDirection="0.7854" />
                    <ctlr:Screw Canvas.Left="4" Canvas.Bottom="4" Size="7" SlitDirection="2.0943" />
                    
                    <Ellipse Width="100" Height="100" 
                        Stroke="{StaticResource CircularBevelBrush}" StrokeThickness="1" />
                </Canvas>

                <StackPanel Width="100" Height="100" Orientation="Vertical">
                    <Label HorizontalAlignment="Center" Margin="0,22,0,0" Padding="3,0,3,1"
                           FontSize="10" Foreground="#00FF77" Background="#161616" BorderBrush="#303030" BorderThickness="0.3"
                           Content="{Binding Source={StaticResource ViewModelLocator}, Path=WeatherViewModel.TemperatureString}" />
                    <Label HorizontalAlignment="Center" Margin="0,32,0,0" Padding="2" FontSize="4" 
                           Foreground="{Binding Source={StaticResource ViewModelLocator}, Path=WeatherViewModel.InfoDisplayStatus, Converter={StaticResource InfoDisplayStatusToBrush}}" 
                           Background="#161616" BorderBrush="#303030" BorderThickness="0.3"
                           Content="{Binding Source={StaticResource ViewModelLocator}, Path=WeatherViewModel.InfoDisplayString}" />
                </StackPanel>
                
                <Canvas Width="100" Height="100">
                    <ctlr:WindDirectionDisplay 
                        WindSpeed="{Binding Source={StaticResource ViewModelLocator}, Path=WeatherViewModel.WeatherInfo.WindSpeed}" 
                        WindDirection="{Binding Source={StaticResource ViewModelLocator}, Path=WeatherViewModel.WeatherInfo.WindDirection}" />
                </Canvas>
            </Grid>
        </Viewbox>

        <ctlr:UserSettingsControl DataContext="{Binding Source={StaticResource ViewModelLocator}, Path=UserSettingsViewModel}"
                                  Visibility="{Binding Source={StaticResource ViewModelLocator}, Path=WeatherViewModel.IsSettingsLayerVisible, Converter={StaticResource BooleanToVisibility}}"/>
    </Grid>
</Window>
